import { createStore } from 'redux'

/**
 * createStore(reducer)
 */

 const reducer = (state = {
   nub: 1,
   name: 'kkb'
 }, action) => {
   switch(action.type){
     case 'EDIT':
       return {
         ...state,
         nub: state.nub + 1
       }
   }
   return state;
 }

 let store = createStore(reducer);

 setInterval(() => {
   // dispatch 默认是同步操作
   store.dispatch({
     type: 'EDIT'
   })
  //  console.log(store.getState());
 }, 1000)

 // 监听state
store.subscribe(() => {
  console.log(store.getState());
})

 /**
  * 四个方法
  * - getState() 获取当前store中的state
  * - dispatch(action) 修改state
  * - subscribe(listener) 监听state
  * - replaceReducer(nextReducer) 替换原来的reducer
  */
console.log(store);
console.log(store.getState());